﻿using System;
using System.Collections.Generic;
using System.Text;
using A2Z.BusinessObjects;
using System.Data;

namespace A2Z.DataObjects
{
    class SqlServerProjectImageDao:IProjectImageDao
    {
        #region IProjectImageDao Members

        public List<ProjectImage> GetProjectImages()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(" SELECT * ");
            sql.Append(" FROM tblProjectImage");

            DataTable dt = Db.GetDataTable(sql.ToString());

            List<ProjectImage> list = new List<ProjectImage>();
            foreach (DataRow row in dt.Rows)
            {
                int id = int.Parse(row["ProjectImageID"].ToString());
                string title = row["Title"].ToString();
                string linkUrl = row["LinkUrl"].ToString();
                string imageUrl = row["ImageUrl"].ToString();
                string type = row["Type"].ToString();

                list.Add(new ProjectImage(id,title,linkUrl,type,imageUrl));
                
            }
            return list;
        }

        public ProjectImage GetProjectImagesByID(int id)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(" SELECT *");
            sql.Append("   FROM tblProjectImage");
            sql.Append("  WHERE ProjectImageID = " + id);

            DataRow row = Db.GetDataRow(sql.ToString());

           
            string title = row["Title"].ToString();
            string linkUrl = row["LinkUrl"].ToString();
            string imageUrl = row["ImageUrl"].ToString();
            string type = row["Type"].ToString();

            return new ProjectImage(id, title, linkUrl, type, imageUrl);

           
        }

        public void Insert(ProjectImage projectImage)
        {
            StringBuilder sql = new StringBuilder();

            //sql.Append(" UPDATE tblProjectImage ");
            //sql.Append("  SET  = " + Db.Escape(customer.Company) + ", ");
            //sql.Append("      City = " + Db.Escape(customer.City) + ", ");
            //sql.Append("      Country = " + Db.Escape(customer.Country) + " ");
            //sql.Append("  WHERE CustomerId = " + customer.CustomerId);

            //return Db.Update(sql.ToString());

           
        }

        public int Update(ProjectImage projectImage)
        {
            //StringBuilder sql = new StringBuilder();

            //sql.Append(" UPDATE Customer ");
            //sql.Append("  SET CompanyName = " + Db.Escape(customer.Company) + ", ");
            //sql.Append("      City = " + Db.Escape(customer.City) + ", ");
            //sql.Append("      Country = " + Db.Escape(customer.Country) + " ");
            //sql.Append("  WHERE CustomerId = " + customer.CustomerId);

            //return Db.Update(sql.ToString());
            return 0;
        }

        public int Delete(ProjectImage projectImage)
        {
            return 0;
        }

        #endregion
    }
}
